<?php
class CaracteristicasController extends AppController {

	var $name = 'Caracteristicas';
	var $helpers = array('Html', 'Form', 'Javascript');

	function index() {
		$this->Caracteristica->recursive = 0;
		$this->set('caracteristicas', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Caracteristica.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('caracteristica', $this->Caracteristica->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Caracteristica->create();
			if ($this->Caracteristica->save($this->data)) {
				$this->Session->setFlash(__('The Caracteristica has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Caracteristica could not be saved. Please, try again.', true));
			}
		}
		$clasificados = $this->Caracteristica->Clasificado->find('list');
		$categorias = $this->Caracteristica->Categoria->find('list');
		$this->set(compact('clasificados', 'categorias'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Caracteristica', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Caracteristica->save($this->data)) {
				$this->Session->setFlash(__('The Caracteristica has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Caracteristica could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Caracteristica->read(null, $id);
		}
		$clasificados = $this->Caracteristica->Clasificado->find('list');
		$categorias = $this->Caracteristica->Categoria->find('list');
		$this->set(compact('clasificados','categorias'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Caracteristica', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Caracteristica->del($id)) {
			$this->Session->setFlash(__('Caracteristica deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}


	function admin_index() {
	if(isset($this->params['admin']) && $this->params['admin']) {
		// check that a user is logged in
		    $this->check_user();
	    }
	$this->layout = "admin";
		$this->Caracteristica->recursive = 0;
		$this->set('caracteristicas', $this->paginate());
	}

	function admin_view($id = null) {
			if(isset($this->params['admin']) && $this->params['admin']) {
		// check that a user is logged in
		    $this->check_user();
	    }
	$this->layout = "admin";
		if (!$id) {
			$this->Session->setFlash(__('Invalid Caracteristica.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('caracteristica', $this->Caracteristica->read(null, $id));
	}

	function admin_add() {
			if(isset($this->params['admin']) && $this->params['admin']) {
		// check that a user is logged in
		    $this->check_user();
	    }
	$this->layout = "admin";
		if (!empty($this->data)) {
			$this->Caracteristica->create();
			if ($this->Caracteristica->save($this->data)) {
				$this->Session->setFlash(__('The Caracteristica has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Caracteristica could not be saved. Please, try again.', true));
			}
		}
		$clasificados = $this->Caracteristica->Clasificado->find('list');
		$categorias = $this->Caracteristica->Categoria->find('list', array('fields'=>'nombre', 'conditions'=>array('subcat_id'=>0,'id >'=>0),'order'=>'id ASC'));
		$this->set(compact('clasificados', 'categorias'));
	}

	function admin_edit($id = null) {
			if(isset($this->params['admin']) && $this->params['admin']) {
		// check that a user is logged in
		    $this->check_user();
	    }
	$this->layout = "admin";
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Caracteristica', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Caracteristica->save($this->data)) {
				$this->Session->setFlash(__('The Caracteristica has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Caracteristica could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Caracteristica->read(null, $id);
		}
		$clasificados = $this->Caracteristica->Clasificado->find('list');
	    $categorias = $this->Caracteristica->Categoria->find('list', array('fields'=>'nombre', 'conditions'=>array('subcat_id'=>0,'id >'=>0),'order'=>'id ASC'));
		$this->set(compact('clasificados','categorias'));
	}
	

	function admin_delete($id = null) {
			if(isset($this->params['admin']) && $this->params['admin']) {
		// check that a user is logged in
		    $this->check_user();
	    }
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Caracteristica', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Caracteristica->del($id)) {
			$this->Session->setFlash(__('Caracteristica deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>
